<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use think\Request;

class Mine extends CommonController
{
    public function mine(Request $request)
    {
        $number = $request->cookie('number');
        $user = Db::table('user')->where('number', $number)->find('user');
        $rand = rand();
        $this->assign('rand', $rand);
        $this->assign('user', $user['user']);
        $this->assign('number', $number);
        //return dump($user);
        return $this->fetch('mine');
    }

    public function modifyHead($number)
    {
        $this->assign('number', $number);
        $rand = rand();
        $this->assign('rand', $rand);
        return $this->fetch('modifyHead');
    }

    public function myPage($id)
    {
        $id = getId($id);
        $res = Db::table('page')->where('user_id', $id)->order('page_id desc')->select();
        $this->assign('list', $res);
        //return dump($res);
        return $this->fetch('readPag');

    }

    public function commend($id)
    {
        $id = getId($id);
        $res = Db::table('comment')->alias('c')->join('user u', 'c.user_id=u.user_id')->where('c.user_id', $id)->select();
        $this->assign('list', $res);
        return $this->fetch('readCom');
	}
	
	public function SetUp($id)
	{
		$res = Db::table('user')->where('number',$id)->select();
		$this->assign('list',$res);
		return $this->fetch('mine/SetUp');
	}
    public function User_name_change($id,$name)
    {
        $res = Db::table('user')->where('number',$id)->update(['user'=>$name]);
        return $res;
    }
    public function User_pawd_change($id,$pawd)
    {
        $res = Db::table('user')->where('number',$id)->select();
        // var_dump($res[0]['password']);
        if($res[0]['password']==$pawd)
        return 1;
        else return 0;
    }
    public function User_pawd_changed($id,$pawd)
    {
        $res = Db::table('user')->where('number',$id)->update(['password'=>$pawd]);
        return 1;        
    }
}
